﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>权限管理</title>
    <!--引入文件-->
    <link href="~/Content/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/Content/themes/icon.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-1.8.2.min.js"></script>
    <script src="~/Scripts/jquery.easyui.min.js"></script>
    <script src="~/Scripts/easyui-lang-zh_CN.js"></script>
    <script src="~/Scripts/datapattern.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>

    <script type="text/javascript">
        $(function () {
            //初始化的时候添加Div是隐藏的 display=none
            $("#addDiv").css("display", "none");
            loadData();
        });
        function loadData(pars) {
            $('#tt').datagrid({
                url: '/ActionInfo/GetActionInfoList',
                title: '权限数据表格',
                width: 'auto',
                height: 'auto',
                fitColumns: true, //列自适应
                nowrap: false,
                idField: 'ID',//主键列的列明
                loadMsg: '正在加载权限的信息...',
                pagination: true,//是否有分页
                singleSelect: false,//是否单行选择
                pageSize: 5,//页大小，一页多少条数据
                pageNumber: 1,//当前页，默认的
                pageList: [5, 10, 15],
                queryParams: pars,//往后台传递参数
                columns: [[//c.UserName, c.UserPass, c.Email, c.RegTime
                    { field: 'ck', checkbox: true, align: 'left', width: 50 },
					{ field: 'ID', title: '编号', width: 80 },
					{ field: 'ActionInfoName', title: '权限名称', width: 120 },
                    { field: 'Remark', title: '备注', width: 120 },
					{ field: 'Sort', title: '排序', width: 120 },
                    { field: 'Url', title: '请求地址', width: 120 },
                    { field: 'HttpMethod', title: '请求方式', width: 120 },
                     {
                         field: 'ActionTypeEnum', title: '权限类型', width: 120,
                         formatter: function (value, row, index) {
                             if (value == "1")
                                 return '菜单权限';
                             else
                                 return '普通权限';
                         }
                     },
                    
                    {
                        field: 'SubTime', title: '时间', width: 80, align: 'right',
                        formatter: function (value, row, index) {
                            return (eval(value.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"))).pattern("yyyy-M-d");
                        }
                    },
                     {
                         field: 'Operation', title: '操作', width: 120,
                         formatter: function (value, row, index) {
                             var str = "<a href='javascript:void(0)' ids='" + row.ID + "' class='deletes'>删除</a>";
                             str = str + "&nbsp;<a href='javascript:void(0)' ids='" + row.ID + "' class='edits'>编辑</a>";
                             return str;
                         }
                     }


                ]],
                toolbar: [{
                    id: 'btnDelete',
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        deleteInfo();
                    }
                }, {
                    id: 'btnAdd',
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {

                        addInfo();
                    }
                }, {
                    id: 'btnEidt',
                    text: '编辑',
                    iconCls: 'icon-edit',
                    handler: function () {

                        showEditInfo();
                    }
                }],
                onLoadSuccess:function()
                {
                    $(".deletes").click(function () {
                        alert('数据加载完成!'+ $(this).attr('ids'));
                    });
                }
            });
        }

        //添加数据
        function addInfo() {
            //给IFrame指定页面URL
            $("#addFrame").attr("src", "/ActionInfo/ShowAddInfo");
            //显示
            $("#addDiv").css("display", "block");
            //以Dialog的方式展示
            $('#addDiv').dialog({
                title: '添加权限数据',
                width: 300,
                height: 300,
                collapsible: true,
                maximizable: true,
                resizable: true,
                modal: true,
                buttons: [{
                    text: 'Ok',
                    iconCls: 'icon-ok',
                    handler: function () {


                        //不同窗体
                        //表示获取了嵌入在主窗体ifrom中的子窗体的windows对象
                        var childwindow = $("#addFrame")[0].contentWindow;
                        //console.warn(childwindow);
                        //调用子窗体中的方法完成表中的提交
                        childwindow.subForm();

                        //同一个页面下面这个调用
                        //表单校验
                        //validateInfo($("#addForm"));
                        //$("#addForm").submit();//提交表单
                    }
                }, {
                    text: 'Cancel',
                    handler: function () {
                        $('#addDiv').dialog('close');
                    }
                }]
            });

        }


        function afterAdd(data) {


            if (data == "ok") {
                //先关闭窗口后刷新
                $('#addDiv').dialog('close');
                $('tt').datagrid('reload');
            }
        }
    </script>

</head>
<body>
    <div>
        <table id="tt" style="width: 700px;" title="标题，可以使用代码进行初始化，也可以使用这种属性的方式" iconcls="icon-edit"></table>
    </div>

    <!--添加权限-->
    <div id="addDiv" style="display:none">
        <iframe id="addFrame" style="width:100%;height:100%" frameborder="0"></iframe>
    </div>
</body>
</html>
